package app.view.mediators
{

	
	import app.AppConstants;
	
	import flash.display.DisplayObject;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	


	public class ApplicationMediator extends Mediator
	{
		public static const NAME: String = "ApplicationMediator"
		
		
		public function ApplicationMediator( viewComponent:Object ):void {
			
			super( NAME, viewComponent);
		}
		
		override public function listNotificationInterests():Array{
			return [ 	AppConstants.ATTACH_TO_APP_DISPLAY,
						AppConstants.REMOVE_FROM_APP_DISPLAY,
						AppConstants.DISABLE_APPLICATION_DISPLAY,
						AppConstants.ENABLE_APPLICATION_DISPLAY	]
		}
		
		override public function handleNotification(notification:INotification):void{
			
			switch( notification.getName() ){
				
				case AppConstants.ATTACH_TO_APP_DISPLAY:
					addChildToView( DisplayObject( notification.getBody() ) );
					break;
					
				case AppConstants.REMOVE_FROM_APP_DISPLAY:
					removeChildFromView( DisplayObject( notification.getBody() ) );
					break;
				
				case AppConstants.DISABLE_APPLICATION_DISPLAY:
					disableDisplay();
					break;
					
				case AppConstants.ENABLE_APPLICATION_DISPLAY:
					enableDisplay();
					break;
					
					
			}
			
		}
		
		private function disableDisplay():void{
			if( !view.mouseChildren )return;
			view.alpha = .5;
			view.mouseChildren = false;

		}
		

		private function enableDisplay():void{
			if( view.mouseChildren )return;
			view.alpha = 1;
			view.mouseChildren = true;

		}
		
		private function addChildToView( child:DisplayObject ):void{
			view.addChild( child );
		}
		
		private function removeChildFromView( child:DisplayObject ):void{
			if( view.contains( child ) ) view.removeChild( child );
		}
		
		public function get view():Main{
			return Main( viewComponent );
		}
		
		
		
	}
}